home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * $ FILE : main.c
- * $ VERSION : 1
- * $ REVISION : 2
- * $ DATE : 08-Dec-93 18:21
- * $
- * $ Author : mvk
- * $
- *
- *
- ** This demo shows the easy way to create
- ** EGS-menus. See InitMenu.c for the menu stuff.
- ** The other routines are for OpenLibs, Event
- ** and error handling.
- **
- ** In these files you will find some useful routines
- ** for Open / Close libraries and error handling.
- **
- ** (c) by VIONA-Development
- **
- */
-
- #include "includes.c"
- #include "Global.h"
- #include "Eventloop.c"
- #include "InitMenu.c"
-
- BOOL InitLibraries(struct OpenStructTyp *);
- void CloseLibraries(struct OpenStructTyp *);
-
- /*
- ** Opens the libs form the OpenStructTyp
- ** (see global.h)
- **
- */
-
- BOOL
- InitLibraries(struct OpenStructTyp *OS)
- {
- struct OpenStructTyp *p = &OS[0];
-
- while (p->Var != NULL)
- {
- if ((*(p->Var) = (ULONG) OpenLibrary(p->Name, p->Version)) == NULL)
- {
- printf(" Can't open %s version %d", p->Name, p->Version);
- return FALSE;
- }
- else
- {
- p++;
- }
- }
- return TRUE;
- }
-
-
- /*
- ** Close the Libs from the OpenStructTyp
- **
- */
-
- void
- CloseLibraries(struct OpenStructTyp *OS)
- {
- struct OpenStructTyp *p = &OS[0];
-
- while (p->Name != NULL)
- {
- CloseLibrary((void *) (*(p->Var)));
- *(p->Var) = NULL;
- p++;
- }
- }
-
- /*
- ** This routine is for Errorhandling.
- ** It close all open thinks form the
- ** program.
- **
- */
- void
- myError(char *string)
- {
- if (string != NULL)
- {
- if (EGSRequestBase == NULL)
- {
- printf("%s\n", string);
- }
- else
- {
- ErrorReq = (ER_SimpleReqPtr) ER_CreateSimpleReq(NULL,
- (char *) string, (char *) "OK");
- /*
- ** Open Requester in the middle of the Screen,
- **
- ** if you could !?
- */
-
- ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
-
- ER_DoRequest(&(ErrorReq->Req));
- }
- }
- if (Window)
- {
- ErrorReq = ER_CreateSimpleReq(NULL,
- "Hello world !|This is a Requester !", "OK");
-
- ErrorReq->Req.Nw->Flags |= EI_WINDOWCENTER;
- ER_DoRequest(&(ErrorReq->Req));
- }
- if (Window)
- EI_CloseWindow(Window);
-
- if (Menu)
- EI_FreeMenu(Menu);
-
- if (FontforMenu)
- EG_CloseFont(FontforMenu);
-
- if (ErrorReq)
- ER_DeleteRequest(&(ErrorReq->Req));
-
- CloseLibraries(OpenStruct);
- exit(0);
- }
-
-
- int
- main(int argc, char *argv[])
- {
- if (argc == 2 && strcmp("?", argv[1]) == 0)
- {
- printf("Aufruf: %s\n Markus van Kempen 12 Nov 1992", argv[0]);
- }
- else
- {
- if (InitLibraries(OpenStruct) == FALSE)
- myError("Can't OpenLibrary");
-
- FontforMenu = (EG_EFontPtr) EG_OpenFont((struct TextAttr *) & FontStr);
-
- if (FontforMenu == NULL)
- myError("Could not open font");
-
- Menu = InitMenu(FontforMenu);
-
- if (Menu == NULL)
- myError("Could not build menu");
-
- newwin.Menu = Menu;
-
- Window = (EI_WindowPtr) EI_OpenWindow((struct EI_NewWindow *) & newwin);
-
- if (Window)
- {
- HandleEvents(Window);
- }
- else
- {
- myError("Could not open window");
- }
- }
- myError(NULL);
- }
-
-